public class Volatile {
    public static int isQuit = 0;   //此时若不用volatile修饰，编译器自动修饰load操作t1线程不结束
    public static void main(String[] args) {

        Thread t1 = new Thread(()-> {
            while(isQuit == 0){

            }
            System.out.println("循环结束");
        });

        Thread t2 = new Thread(()-> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            isQuit = 1;
        });
        t1.start();
        t2.start();
    }
}
